package personal.wang.cf;


import java.util.concurrent.CompletionException;

/**
 * @className: ExceptionUtils
 * @Description:
 * @Author: wangyifei
 * @Date: 2025/3/27 11:07
 */
public class ExceptionUtils {

    public static Throwable stripException(
            Throwable throwableToStrip, Class<? extends Throwable> typeToStrip) {
        while (typeToStrip.isAssignableFrom(throwableToStrip.getClass())
                && throwableToStrip.getCause() != null) {
            throwableToStrip = throwableToStrip.getCause();
        }

        return throwableToStrip;
    }

    public static  Throwable stripExecutionException(Throwable throwable) {
        return stripException(throwable, CompletionException.class);
    }
}
